# coding:utf-8
# author:frank
# date:2024/12/31
import pygame

pygame.init()

# pygame.Rect()和pygame.draw.rect()的区别
# pygame.Rect()用于创建一个矩形对象，可以用于碰撞检测等操作
# pygame.draw.rect()用于在窗口中绘制一个矩形

# pygame.Rect() 需要使用pygame.draw.rect()将其渲染在界面上
rect1 = pygame.Rect(0, 100, 50, 50)
rect2 = pygame.Rect(300, 100, 50, 50)
font = pygame.font.Font(None, 36)
text = font.render("撞上了",True, (255, 0, 0))
win_w=500
win_h=600
win = pygame.display.set_mode((win_w,win_h))
pygame.display.set_caption("标题模板")
win.fill('white')
pygame.display.flip()

while True:
    pygame.time.Clock().tick(30)
    win.fill('white')
    rect1.x += 1
    rect2.x -= 1
    if rect1.colliderect(rect2):
        win.blit(text, (win_w/2-50, win_h/2-50))
    pygame.draw.rect(win, (255, 0, 0), rect1)
    pygame.draw.rect(win, (0, 255, 0), rect2)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()